package cz.possoft.explorer.resolver.method;

/**
 * Key for methods (instances of java.lang.reflect.util.Method) . Key can be used to identify method by name of method and arguments.
 *  
 * 
 * @author <a href="mailto:mposolda@gmail.com">Marek Posolda</a>
 * @version $Revision$
 */
public final class MethodKey
{
   private final String methodName;
   
   private final Class<?>[] classes;
   
   public MethodKey(String methodName, Class<?>[] classes)
   {
      this.methodName = methodName;
      this.classes = classes;
   }  
   
   public String getMethodName()
   {
      return methodName;
   }

   public Class<?>[] getClasses()
   {
      return classes;
   }

   public boolean equals(Object o)
   {
      if (!(o instanceof MethodKey))
      {
         return false;         
      }
      MethodKey that = (MethodKey)o;
      
      // compare methodName
      if (!methodName.equals(that.methodName))
      {
         return false;
      }
      
      // compare classes
      if (classes.length != that.classes.length)
      {
         return false;
      }
      for (int i=0 ; i<classes.length ; i++)
      {
         if (!classes[i].equals(that.classes[i]))
         {
            return false;
         }
      }
      
      return true;
   }
   
   public int hashCode()
   {
      int semi = 1;
      for (int i=0 ; i<classes.length ; i++)
      {
         semi = semi + i * classes[i].hashCode();
      }
      
      return semi + methodName.hashCode() * 17;
   }

}

